<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>刘超的博客</title><meta name="author" content="刘超"><meta name="copyright" content="刘超"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="只有自己强大，才不会被别人践踏。">
<meta property="og:type" content="website">
<meta property="og:title" content="刘超的博客">
<meta property="og:url" content="https://leachliu.gitee.io/index.html">
<meta property="og:site_name" content="刘超的博客">
<meta property="og:description" content="只有自己强大，才不会被别人践踏。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://leachliu.gitee.io/images/avatar.webp">
<meta property="article:author" content="刘超">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://leachliu.gitee.io/images/avatar.webp"><link rel="shortcut icon" href="/images/favicon.ico"><link rel="canonical" href="https://leachliu.gitee.io/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: {"appId":"VFZO06XK8A","apiKey":"1202cec78a85d208874b3c9cbcd0e212","indexName":"index total","hits":{"per_page":10},"languages":{"input_placeholder":"搜索文章","hits_empty":"找不到您查询的内容：${query}","hits_stats":"找到 ${hits} 条结果，用时 ${time} 毫秒"}},
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '刘超的博客',
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2023-11-06 16:30:51'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><link rel="stylesheet" href="https://npm.elemecdn.com/ethan4116-blog/lib/css/plane_v2.css"><link rel="stylesheet" href="https://fastly.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css"  media="defer" onload="this.media='all'"><script defer src="/js/custom.js"></script><link rel="stylesheet" href="https://fastly.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"><link rel="stylesheet" href="/css/universe.css"><link rel="stylesheet" href="/css/custom.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css" media="defer" onload="this.media='all'"><script src="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 7.0.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/images/avatar.webp" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">41</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">21</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="刘超的博客"><span class="site-name">刘超的博客</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/05/23/home/" title="写博客的初衷"><i class="fas fa-thumbtack sticky"></i>写博客的初衷</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-05-23T05:40:00.000Z" title="发表于 2021-05-23 13:40:00">2021-05-23</time></span></div><div class="content">写博客这件事已经想做了很久,但由于各种原因一直拖到现在。一开始是不知道自己想写什么内容,另外一方面自己的知识储备少,遇到的问题和困难也比较少,所以一直没有推动这个事情.&lt;/br&gt;

为什么要写博客对于我个人而言,主要有以下几个原因
记录自己学习、思考、总结的过程
分享自己的故事、所得、感想、经验、帮助他人少走弯路
在总结和讨论中了解自己、提升自己
寻找志同道合的朋友
为以后的工作历程奠定一个好的基础

我想用博客记录下来我学习,思考和总结的过程,就像用日记照片和视频去记住逝去的日子一样,正是这些逝去的点点滴滴,才形成现在的我。而这些过程使我收益,我相信你们遇到同样的问题时,或许也能从中收益一些。而且我觉得就算没人看我的博客,总结本身就是一个很好的过程,在这个过程中我们再次思考之前遇到的问题,从而巩固知识。当然如果能发现漏洞那就更好了,可以纠正自己的错误扩展知识面。我觉得由一个初学者(我自认为还是一个初学者,哈哈),学会之后写出来的东西可能会比领域内资深的人写出来的更加适合初学者。因为刚刚学会的初学者更加清楚学习过程中遇到一些什么样的问题,同时他们的语言更简单,虽然可能语言没 ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2023/11/06/comlibary/4.%E7%BB%84%E4%BB%B6%E5%BA%93%E7%B1%BB%E5%90%8D%E6%96%B9%E6%B3%95%E5%AE%9E%E7%8E%B0%E4%BB%A5%E5%8F%8A%E8%A7%84/" title="无题">无题</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-11-06T07:16:00.298Z" title="发表于 2023-11-06 15:16:00">2023-11-06</time></span></div><div class="content"></div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/11/06/comlibary/3.%E6%90%AD%E5%BB%BA%E7%BB%84%E4%BB%B6%E5%BA%93%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/" title="组件库框架 - 3 搭建组件库开发环境"><img class="post-bg" src="/images/beijing4.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="组件库框架 - 3 搭建组件库开发环境"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/11/06/comlibary/3.%E6%90%AD%E5%BB%BA%E7%BB%84%E4%BB%B6%E5%BA%93%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/" title="组件库框架 - 3 搭建组件库开发环境">组件库框架 - 3 搭建组件库开发环境</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-11-06T06:30:00.000Z" title="发表于 2023-11-06 14:30:00">2023-11-06</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%BB%84%E4%BB%B6%E5%BA%93/">组件库</a></span></div><div class="content">前文已经初始化了 workspace-root，从本文开始就需要依次搭建组件库、example、文档、cli。本文内容是搭建 组件库的开发环境。
1 packages 目录前面在项目根目录下创建了 packages 目录，该目录存放组件库的所有组件及组件库的入口。该目录中已经创建了两个子目录 preview 和 leach-demo-ui。这两个目录是干嘛用的呢？

preview 目录preview 目录代表一个示例项目，后面咱们会引用组件库、测试组件库是否能正常运行。

leach-demo-ui 目录leach-demo-ui 目录存放组件库的入口，在该目录下创建 index.ts 文件，该文件是组件库的入口文件。


2 初始化leach-demo-ui组件库目录   在命令行中进入 leach-demo-ui 目录

创建 index.ts 文件，该文件为组件的入口文件：touch index.ts
创建 src 目录，该目录存放组件的实现源码。在 leach-demo-ui/src/ 中创建 index.ts 它是所有组件的全部导出如此一来，示例组件 foo 的目录结构便创 ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2023/11/06/comlibary/2.%E5%88%9D%E5%A7%8B%E5%8C%96workspace-root/" title="组件库框架 - 2 初始化workspace-root"><img class="post-bg" src="/images/beijing4.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="组件库框架 - 2 初始化workspace-root"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/11/06/comlibary/2.%E5%88%9D%E5%A7%8B%E5%8C%96workspace-root/" title="组件库框架 - 2 初始化workspace-root">组件库框架 - 2 初始化workspace-root</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-11-06T03:18:00.000Z" title="发表于 2023-11-06 11:18:00">2023-11-06</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%BB%84%E4%BB%B6%E5%BA%93/">组件库</a></span></div><div class="content">&emsp;上文已经搭建了 pnpm + monorepo 的基础环境，本文对 workspace-root 进行初始化配置，包括：通用配置文件、公共依赖、ESLint。

通用配置文件在项目 根目录 下添加下面的配置文件。

添加 .editorconfig 编辑器格式配置文件

[*.&#123;js,cjs,ts,jsx,tsx,vue,html,css,scss,md&#125;]indent_style = spaceindent_size = 2trim_trailing_whitespace = trueinsert_final_newline = true

添加 .gitignore git 忽略文件

logs*.log*node_modulesdistlibdist-ssr*.local.vscode/*!.vscode/extensions.json.idea.DS_Store*.suo*.ntvs**.njsproj*.sln*.sw?
说明：在有些文章中还会创建一个 .npmrc 文件，配置 shamefully-hoist 为 true，该操作的目的是进行 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/10/27/comlibary/1.%E6%90%AD%E5%BB%BApnpm%E3%80%81monorepo/" title="组件库框架 - 1 搭建pnpn monorepo"><img class="post-bg" src="/images/beijing3.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="组件库框架 - 1 搭建pnpn monorepo"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/10/27/comlibary/1.%E6%90%AD%E5%BB%BApnpm%E3%80%81monorepo/" title="组件库框架 - 1 搭建pnpn monorepo">组件库框架 - 1 搭建pnpn monorepo</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-10-27T06:36:00.000Z" title="发表于 2023-10-27 14:36:00">2023-10-27</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%BB%84%E4%BB%B6%E5%BA%93/">组件库</a></span></div><div class="content">组件库搭建&emsp;需求需要自己从 0-1 封装一个组件库，在此记录一下如何从 0-1 完成的过程，首先记录一下如何搭建框架,例如 git husky 、commlint、eslint、prettier 配置这些也会讲解，后面会讲如何封装一些常用的公共组件，例如 Select、Input、Form 等。

组件库工程应该具备的功能
在参考 Element Plus、Ant Design、Van UI 等 Vue3 开源 UI 项目后，我认为一套企业组件库工程需要具备如下功能;

组件库的开发：这是最基础的，组件库工程必须要支持组件库的开发，在工程中开发各种组件；
组件库的构建：组件库开发完成后，不可能让所有使用该组件库的项目都使用源码的方式引入到各个项目中，而是要将其构建打包后发布到私服或 npm 上，各个项目通过依赖的方式引入使用。在这个过程中，就涉及类型定义的提取、不同模块化规范的打包等；组件库的发布：上面提到组件库构建打包后需要发布到私服或 npm，那难道在组件库开发阶段就频繁的发布到私服上吗？这样做也没问题。不过优雅哥的建议是在本地启动一个迷你私服，当组件库开发到一个阶段（如 ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2023/01/12/other/%E4%BD%BF%E7%94%A8OSS+PicGo%E6%90%AD%E5%BB%BA%E5%9B%BE%E5%BA%8A/" title="使用OSS+PicGo搭建图床"><img class="post-bg" src="https://chao-picture-bed.oss-cn-hangzhou.aliyuncs.com/blog/vue/popperJs/202301121557184.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="使用OSS+PicGo搭建图床"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/01/12/other/%E4%BD%BF%E7%94%A8OSS+PicGo%E6%90%AD%E5%BB%BA%E5%9B%BE%E5%BA%8A/" title="使用OSS+PicGo搭建图床">使用OSS+PicGo搭建图床</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-01-12T07:39:00.000Z" title="发表于 2023-01-12 15:39:00">2023-01-12</time></span></div><div class="content">前言目前写博客需要用到很多图片或者其他资源,直接链接网络资源可能因为外链禁止访问(例如 gitee 403 forbidden)或者是本地资源存储造成文件过大或者是需要 base64 转换麻烦，所以采用 OSS+PicGo 搭建图床

学习文档阿里云-对象存储 OSSOSS 服务
购买资源包首先消费马内购买资源包， 这个位置我之前已经买过了，所以有提示，个人建议买最低的就够用了。
创建 Bucket(存储桶)以及存储目录
读写权限设置
新建文件目录
创建用户，分配权限点击创建用户入口
创建用户

创建成功
用户登录名称 leachliu99@xxxxxx9156444.onxxxxyun.comAccessKey ID：LTAI5tC8Exxpoxw68xxexKbAccessKey Secret：Ynxf9uqrxPxgxxxQLCx9xRxHxscBUF
AccessKey Secret 只有才创建的时候才会出现,后续进入是不会出现的，除非删除掉，重新新增一个用户，会出现一个 csv 文件，最好是下来以便日后插用

添加权限

获取存储区域：注意注意，仅仅是取 oss-cn-han ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/12/31/vue/%E4%BD%BF%E7%94%A8popperJs%E5%B0%81%E8%A3%85%E6%B0%94%E6%B3%A1%E5%8D%A1%E7%BB%84%E4%BB%B6/" title="vue2使用popperJs封装气泡卡片"><img class="post-bg" src="/images/beijing3.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="vue2使用popperJs封装气泡卡片"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/12/31/vue/%E4%BD%BF%E7%94%A8popperJs%E5%B0%81%E8%A3%85%E6%B0%94%E6%B3%A1%E5%8D%A1%E7%BB%84%E4%BB%B6/" title="vue2使用popperJs封装气泡卡片">vue2使用popperJs封装气泡卡片</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-12-31T01:49:00.000Z" title="发表于 2022-12-31 09:49:00">2022-12-31</time></span></div><div class="content">前言目前业务需求需要涉及到封装卡片组件需求，需要根据气泡卡片到视口一定安全距离自动转换方向,以及涉及到 web 端和 H5 端同弹窗卡片不样式要求。

实现需求

符合 UI 视觉规范要求
点击或者鼠标触摸触发容器卡片上下或者左右滑动时遇到临界值自动转向
兼容旧组件样式和业务需求

popper.js 是一款功能强大的 JS 定位引擎。最近在写 tooltip 弹窗时，需要用到提示框定位的问题，然后度娘推荐我使用 popper.js 库，查看了 iview 库和 element 库的源码，发现定位都是用的这个玩意儿。既然大佬们都在用这个，我也去 Popper.js 官网瞅了下，没有中文文档，不得不吐槽一下。
下载yarn add @popperjs/core
使用方法var popperInstance = new Popper(reference,popper,options);
下面会介绍到封装组件用到的一些popper.js 参数配置，如果想详细了解可以去 官方文档
Popper 构造函数接收三个参数:
reference(指代下文的 trigger) 是要定位到的 HTMLEl ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2022/08/31/vue/vue%E9%A1%B9%E7%9B%AE%E8%A7%84%E8%8C%83/" title="vue项目规范"><img class="post-bg" src="/images/vue_%20project_spe_cover.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="vue项目规范"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/08/31/vue/vue%E9%A1%B9%E7%9B%AE%E8%A7%84%E8%8C%83/" title="vue项目规范">vue项目规范</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-08-31T08:00:00.000Z" title="发表于 2022-08-31 16:00:00">2022-08-31</time></span></div><div class="content">Vue 目录文件夹及子文件规范
以下统一管理处均对应相应模块
以下全局文件文件均以 index.js 导出，并在 main.js 中导入
以下临时文件，在使用后，接口已经有了，发版后清除

src                               源码目录  |-- api                              接口，统一管理  |-- assets                           静态资源，统一管理  |-- components                       公用组件，全局文件  |-- filters                          过滤器，全局工具  |-- icons                            图标，全局资源  |-- datas                            模拟数据，临时存放  |-- lib                              外部引用的插件存放及修改文件  |-- mock                      ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/08/25/js/%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%B8%8E%E6%9C%8D%E5%8A%A1%E7%AB%AF%E6%B8%B2%E6%9F%93%E8%AF%A6%E8%A7%A3/" title="客户端渲染和服务器渲染详解"><img class="post-bg" src="/images/ssg_ssr_cover.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="客户端渲染和服务器渲染详解"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/08/25/js/%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%B8%8E%E6%9C%8D%E5%8A%A1%E7%AB%AF%E6%B8%B2%E6%9F%93%E8%AF%A6%E8%A7%A3/" title="客户端渲染和服务器渲染详解">客户端渲染和服务器渲染详解</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-08-24T16:00:00.000Z" title="发表于 2022-08-25 00:00:00">2022-08-25</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/javaScript/">javaScript</a></span></div><div class="content">客户端渲染
图片详解

文字详解

首先用户输入地址，客户端（浏览器)向服务端发送请求
服务器向客户端（浏览器)传送相应的网页文件
浏览器解析文件
遇到 ajax 请求则再次向服务器发送一次请求 请求数据
客户端（浏览器)拿到 ajax 请求返回的数据后，将数据渲染在页面上



客户端渲染案例上面已经介绍了，在没有请求数据时已经开始渲染了,只是有些数据没拿到，不过大部分页面内容我们都已经看到了,所以客户端渲染可以完成页面的局部刷新
在点击下一页评论,页面没有刷新,地址没有变化,只有评论的内容做了一个 ajax 局部刷新,这就是一个典型的客户端渲染的例子,进入这个页,其他的内容都被浏览器渲染好了,而评论信息点击下一页时,客户端向服务器发送 ajax 请求,拿到了这一页的评论信息,再在这个部分做一个局部的数据重新渲染
优点
可以向用户快速展示页面内容,增加用户体验
数据请求时不会刷新页面 重新请求页面

缺点
可能需要多次请求数据
不利于 SEO 搜索引擎优化

服务端渲染
图片详解

文字详解



首先客户端向服务端发送一次请求
服务端接收请求，并在服务端操作网页文件,将对应数据导入 ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2022/08/16/js/%E6%B1%82%E5%87%BA%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC/" title="求出数组中最大的值">求出数组中最大的值</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-08-15T16:00:00.000Z" title="发表于 2022-08-16 00:00:00">2022-08-16</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/javaScript/">javaScript</a></span></div><div class="content">查找数组中最大值的 4 种方法排序法首选给数组中的数字进行排序,可以从小到大进行排序,排列之后的数组中最后一项和第一项就是我们想获得的最大的值和最小的值。
  var arr = [12,56,25,5,82,51,22];arr.sort((a,b)=&gt;&#123; return a - b&#125;) // [5,12,22,25,51,56,82]var min = arr[0];var max = arr[at-1];

假设法假设当前数组中第一个值为最大值,然后循环便利拿最大值和其他值逐一比较,如果当前循环数字比最大值大,则进行赋值
  var arr = [12,56,25,5,82,51,22];var max = arr[0];for(i = 0 ; i&lt; arr.length;i++)&#123;  arr[i] &gt; max ? max = arr[i] : null&#125;console.log(max) //82//反之最小值小于赋值就行

使用 Math 中的 max&#x2F;min 方法可以使用 apply 来实现。apply 传入的 ...</div></div></div><nav id="pagination"><div class="pagination"><span class="page-number current">1</span><a class="page-number" href="/page/2/#content-inner">2</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/#content-inner">5</a><a class="extend next" rel="next" href="/page/2/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/images/avatar.webp" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">刘超</div><div class="author-info__description">只有自己强大，才不会被别人践踏。</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">41</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">21</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="http://wpa.qq.com/msgrd?v=3&amp;uin=923946406&amp;site=qq&amp;menu=yes" target="_blank" title="QQ"><i class="fab fa-qq"></i></a><a class="social-icon" href="https://chao-picture-bed.oss-cn-hangzhou.aliyuncs.com/blog/vue/popperJs/202301131417748.jpg" target="_blank" title="Wechat"><i class="fab fa-weixin"></i></a><a class="social-icon" href="/923946406@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://github.com/tzy13755126023" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title="Rss"><i class="fas fa-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">书山有路勤为径,学海无涯苦作舟</div></div><div class="card-widget tzy-right-widget" id="card-wechat"><div id="flip-wrapper"><div id="flip-content"><div class="face"></div><div class="back face"></div></div></div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/11/06/comlibary/4.%E7%BB%84%E4%BB%B6%E5%BA%93%E7%B1%BB%E5%90%8D%E6%96%B9%E6%B3%95%E5%AE%9E%E7%8E%B0%E4%BB%A5%E5%8F%8A%E8%A7%84/" title="无题">无题</a><time datetime="2023-11-06T07:16:00.298Z" title="发表于 2023-11-06 15:16:00">2023-11-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/11/06/comlibary/3.%E6%90%AD%E5%BB%BA%E7%BB%84%E4%BB%B6%E5%BA%93%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/" title="组件库框架 - 3 搭建组件库开发环境"><img src="/images/beijing4.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="组件库框架 - 3 搭建组件库开发环境"/></a><div class="content"><a class="title" href="/2023/11/06/comlibary/3.%E6%90%AD%E5%BB%BA%E7%BB%84%E4%BB%B6%E5%BA%93%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/" title="组件库框架 - 3 搭建组件库开发环境">组件库框架 - 3 搭建组件库开发环境</a><time datetime="2023-11-06T06:30:00.000Z" title="发表于 2023-11-06 14:30:00">2023-11-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/11/06/comlibary/2.%E5%88%9D%E5%A7%8B%E5%8C%96workspace-root/" title="组件库框架 - 2 初始化workspace-root"><img src="/images/beijing4.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="组件库框架 - 2 初始化workspace-root"/></a><div class="content"><a class="title" href="/2023/11/06/comlibary/2.%E5%88%9D%E5%A7%8B%E5%8C%96workspace-root/" title="组件库框架 - 2 初始化workspace-root">组件库框架 - 2 初始化workspace-root</a><time datetime="2023-11-06T03:18:00.000Z" title="发表于 2023-11-06 11:18:00">2023-11-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/10/27/comlibary/1.%E6%90%AD%E5%BB%BApnpm%E3%80%81monorepo/" title="组件库框架 - 1 搭建pnpn monorepo"><img src="/images/beijing3.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="组件库框架 - 1 搭建pnpn monorepo"/></a><div class="content"><a class="title" href="/2023/10/27/comlibary/1.%E6%90%AD%E5%BB%BApnpm%E3%80%81monorepo/" title="组件库框架 - 1 搭建pnpn monorepo">组件库框架 - 1 搭建pnpn monorepo</a><time datetime="2023-10-27T06:36:00.000Z" title="发表于 2023-10-27 14:36:00">2023-10-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/01/12/other/%E4%BD%BF%E7%94%A8OSS+PicGo%E6%90%AD%E5%BB%BA%E5%9B%BE%E5%BA%8A/" title="使用OSS+PicGo搭建图床"><img src="https://chao-picture-bed.oss-cn-hangzhou.aliyuncs.com/blog/vue/popperJs/202301121557184.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="使用OSS+PicGo搭建图床"/></a><div class="content"><a class="title" href="/2023/01/12/other/%E4%BD%BF%E7%94%A8OSS+PicGo%E6%90%AD%E5%BB%BA%E5%9B%BE%E5%BA%8A/" title="使用OSS+PicGo搭建图床">使用OSS+PicGo搭建图床</a><time datetime="2023-01-12T07:39:00.000Z" title="发表于 2023-01-12 15:39:00">2023-01-12</time></div></div></div></div><div class="card-widget card-categories"><div class="item-headline">
            <i class="fas fa-folder-open"></i>
            <span>分类</span>
            
            </div>
            <ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/categories/git/"><span class="card-category-list-name">git</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/html/"><span class="card-category-list-name">html</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/javaScript/"><span class="card-category-list-name">javaScript</span><span class="card-category-list-count">10</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/react/"><span class="card-category-list-name">react</span><span class="card-category-list-count">17</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/webpack/"><span class="card-category-list-name">webpack</span><span class="card-category-list-count">4</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E7%BB%84%E4%BB%B6%E5%BA%93/"><span class="card-category-list-name">组件库</span><span class="card-category-list-count">3</span></a></li>
            </ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/state/" style="font-size: 1.1em; color: #999">state</a> <a href="/tags/tinymce/" style="font-size: 1.23em; color: #999ea6">tinymce</a> <a href="/tags/git/" style="font-size: 1.1em; color: #999">git</a> <a href="/tags/%E5%B8%83%E5%B1%80/" style="font-size: 1.5em; color: #99a9bf">布局</a> <a href="/tags/html/" style="font-size: 1.1em; color: #999">html</a> <a href="/tags/router/" style="font-size: 1.1em; color: #999">router</a> <a href="/tags/cross-env/" style="font-size: 1.1em; color: #999">cross-env</a> <a href="/tags/webpack/" style="font-size: 1.5em; color: #99a9bf">webpack</a> <a href="/tags/redux/" style="font-size: 1.23em; color: #999ea6">redux</a> <a href="/tags/S3/" style="font-size: 1.23em; color: #999ea6">S3</a> <a href="/tags/Array/" style="font-size: 1.37em; color: #99a4b2">Array</a> <a href="/tags/js/" style="font-size: 1.23em; color: #999ea6">js</a> <a href="/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" style="font-size: 1.1em; color: #999">设计模式</a> <a href="/tags/axios/" style="font-size: 1.1em; color: #999">axios</a> <a href="/tags/chrome/" style="font-size: 1.1em; color: #999">chrome</a> <a href="/tags/ssr/" style="font-size: 1.1em; color: #999">ssr</a> <a href="/tags/this/" style="font-size: 1.1em; color: #999">this</a> <a href="/tags/Ref/" style="font-size: 1.1em; color: #999">Ref</a> <a href="/tags/%E7%BB%84%E4%BB%B6%E5%BA%93/" style="font-size: 1.37em; color: #99a4b2">组件库</a> <a href="/tags/react/" style="font-size: 1.23em; color: #999ea6">react</a> <a href="/tags/%E7%BC%96%E8%AF%91/" style="font-size: 1.1em; color: #999">编译</a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span><a class="card-more-btn" href="/archives/" title="查看更多">
    <i class="fas fa-angle-right"></i></a></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/11/"><span class="card-archive-list-date">十一月 2023</span><span class="card-archive-list-count">3</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/10/"><span class="card-archive-list-date">十月 2023</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/01/"><span class="card-archive-list-date">一月 2023</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/12/"><span class="card-archive-list-date">十二月 2022</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/08/"><span class="card-archive-list-date">八月 2022</span><span class="card-archive-list-count">7</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/01/"><span class="card-archive-list-date">一月 2022</span><span class="card-archive-list-count">8</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2021/12/"><span class="card-archive-list-date">十二月 2021</span><span class="card-archive-list-count">6</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2021/09/"><span class="card-archive-list-date">九月 2021</span><span class="card-archive-list-count">5</span></a></li></ul></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023  <i id="heartbeat" class="fa fas fa-heartbeat"></i> 刘超</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><canvas id="universe"></canvas><script defer src="/js/universe.js"></script><script defer src="https://fastly.jsdelivr.net/npm/hexo-theme-volantis@latest/source/js/issues.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="algolia-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="search-wrap"><div id="algolia-search-input"></div><hr/><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-info"><div class="algolia-stats"></div><div class="algolia-poweredBy"></div></div></div></div></div><div id="search-mask"></div><script src="https://cdn.jsdelivr.net/npm/algoliasearch/dist/algoliasearch-lite.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instantsearch.js/dist/instantsearch.production.min.js"></script><script src="/js/search/algolia.js"></script></div></div><!-- hexo injector body_end start --><script async src="//at.alicdn.com/t/font_2032782_8d5kxvn09md.js"></script><!-- hexo injector body_end end --></body></html>